package com.example.validate;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AdminManagementServlet
 */
public class AdminManagementServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private AddReviewServlet encoder;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminManagementServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String fullName = "";
		String shortName = "";
		String place = "";
		String zip = "";
		String schoolCountry = "";
		
		if(request.getParameter("schoolButton") != null){
			fullName = request.getParameter("fullName");
			shortName = request.getParameter("shortName");
			place = request.getParameter("place");
			zip = request.getParameter("zip");
			schoolCountry = request.getParameter("country");
			if(AdminDAO.addSchool(fullName,shortName,place,zip,schoolCountry)){
				request.setAttribute("addSchool", "School was successfully added");
			}else{
				request.setAttribute("addSchool", "School was not successfully added");
			}
		}
		
		String countryShortName = "";
		String countryFullName = "";
		if(request.getParameter("countryButton") != null){
			countryShortName = request.getParameter("countrySN");
			countryFullName = request.getParameter("countryFN");
			if(AdminDAO.addCountry(countryShortName,countryFullName)){
				request.setAttribute("addCountry", "Country was successfully added");
			}else{
				request.setAttribute("addCountry", "Country was not successfully added");
			}
		}
		
		String username = "";
		if(request.getParameter("userButton") != null){
			username = request.getParameter("user");
			if(AdminDAO.removeUser(username)){
				request.setAttribute("userRemoved", "User was successfully removed");
			}else{
				request.setAttribute("userRemoved", "User was not successfully removed");
			}
		}
		request.getRequestDispatcher("lutadmin.jsp").forward(request, response);
	}

}
